package com.sy.common.service;

import com.sy.cloud.guess.model.Heroset;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

/**
 * Created by mac on 2017/11/24.
 */
@Transactional
@Service
@Slf4j
public class SetsService implements ISetsService {
    @Autowired
    private IBaseService baseService;


    /**
     * 英雄的列表
     * @return
     */
    @Override
    public List<Heroset> getList(){
        List<Heroset> herosetList = new ArrayList<Heroset>();

        StringBuilder selectSql0 = new StringBuilder();
        selectSql0.append(" From Heroset u where type = 1");
        herosetList = baseService.listQuery( selectSql0.toString(), Heroset.class );
        return herosetList;
    }

    /**
     * 王者荣耀在线人数的配置列表
     * @return
     */
    public List<Heroset> getList2(){
        List<Heroset> herosetList = new ArrayList<Heroset>();

        StringBuilder selectSql0 = new StringBuilder();
        selectSql0.append(" From Heroset u where type = 2");
        herosetList = baseService.listQuery( selectSql0.toString(), Heroset.class );
        return herosetList;
    }

    /**
     * 名字和id的对应
     * @return
     */
    @Override
    public List<Object[]> getList3(){
        List<Object[]> allList = new ArrayList<Object[]>();

        StringBuilder selectSql0 = new StringBuilder();
        selectSql0.append("select name From Heroset u where 1=1");
//        allList = dbService.getHeroList( selectSql0.toString() );
        allList = baseService.nativeQuery("select id,name,odds from sp_hero_set");
        return allList;
    }

    /**
     * 概率
     * @return
     */
    public Map<String,Double> probaSet(String type){
        Map<String,Double> mapresult = new HashMap<String,Double>();
        Heroset heroset = new Heroset();
        List l0 = new ArrayList();
        if( "hero".equals(type) ){
            l0  = getList();
            Iterator it = getList().iterator();
            while( it.hasNext() ){
                heroset = (Heroset)it.next();
                mapresult.put(heroset.getId().toString(), heroset.getPercent());
            }
        }else if( "digit".equals(type) ){
            l0  = getList2();
            Iterator it = getList().iterator();
            while( it.hasNext() ){
                Heroset digitse = (Heroset)it.next();
                mapresult.put(digitse.getId().toString(), digitse.getPercent());
            }
        }


        return mapresult;
    }

    /**
     * 赔率
     * @return
     */
    @Override
    public Map<Integer,Integer> oddsSet(String type){
        Map<Integer,Integer> mapresult = new HashMap<Integer,Integer>();
        List l0 = new ArrayList();
        if( "hero".equals(type) ){
            l0  = getList();
            Iterator it = l0.iterator();
            while( it.hasNext() ){
                Heroset heroset = (Heroset)it.next();
                mapresult.put( heroset.getId().intValue(), heroset.getOdds());
            }
        }else if( "digit".equals(type) ){
            l0  = getList2();
            Iterator it = l0.iterator();
            while( it.hasNext() ){
                Heroset heroset = (Heroset)it.next();
                mapresult.put( heroset.getId().intValue(), heroset.getOdds());
            }
        }

        return mapresult;
    }



}
